var layer;
var $;
var table;
layui.use(['element','layer','table'], function(){
    layer = layui.layer;
    lement = layui.element;//面包导航
    $ = layui.jquery;
    table = layui.table;
    //用户展示数据
    selUserNum();
    load();
    selPerTab(-1);
    selEcharts(-1);
    //查询用户的统计数据
    selUserEcharts();
    //定时器，每5分钟执行一次
    window.setInterval(selUserNum,300000);
    window.setInterval("selPerTab(-1)",300000);
    window.setInterval("selEcharts(-1)",300000);
    window.setInterval(selUserEcharts,300000);


});
/**
 *   用户数据展示
 * */
function selUserNum(){
    $.ajax({
        url:"/personnel/selUserNum",
        type:"get",
        dataType:"json",
        data:{},
        success:function(data) {
            selUserTab(data);
        }
    })
}
function selUserTab(data){
    $("#today").html(data.userToday);
    $("#yes").html(data.userYes);
    $("#mou").html(data.userMou);
    $("#num").html(data.userNum);
    $("#today1").html(data.userToday);
    $("#yes1").html(data.userYes);
    $("#mou1").html(data.userMou);
    $("#num1").html(data.userNum);
    $("#passNum").html(data.applyPassNum);
    $("#afterNum").html(data.afterUserNum);

    $("#applyWaitNum").html(data.applyWaitNum);
    $("#feekWaitNum").html(data.feedbackWaitNum);
    if(data.applyWaitNum==0){
        $("#aff_apply").css("display","none");
    }else{
        $("#aff_apply").css("display","block");
    }
    if(data.feedbackWaitNum==0){
        $("#aff_feek").css("display","none");
    }else{
        $("#aff_feek").css("display","block");
    }
}
/**
 *   点击事件
 * */
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    })
    $("#echarts_btn1").bind('click',function(){
        $("#echarts_btn1").removeClass("layui-btn-primary");
        $("#echarts_btn2").addClass("layui-btn-primary");
        $("#echarts_btn3").addClass("layui-btn-primary");
        selPerTab(-1);
        selEcharts(-1);
    })
    $("#echarts_btn2").bind('click',function(){
        $("#echarts_btn1").addClass("layui-btn-primary");
        $("#echarts_btn2").removeClass("layui-btn-primary");
        $("#echarts_btn3").addClass("layui-btn-primary");
        selPerTab(-7);
        selEcharts(-7);
    })
    $("#echarts_btn3").click(function(){
        $("#echarts_btn1").addClass("layui-btn-primary");
        $("#echarts_btn2").addClass("layui-btn-primary");
        $("#echarts_btn3").removeClass("layui-btn-primary");
        selPerTab(-30);
        selEcharts(-30);
    })
}
/**
 * 申请统计
 * */
function selPerTab(durDate){
    var table = layui.table;
    table.render({
        elem:"#tabInfo",//容器
        url:"/personnel/selPerTab",
        title:"申请数据统计",
        limit:3,//分页显示条数
        width:595,
        where: {durDate: durDate},
        parseData: function (res) { //res即为原始返回的数据\
            return {
                "code": 0,
                "msg": "",
                "count": 1000,
                "data": res
            }
        },
        page:false,
        cols:[[//定义列
            {field:"applyNum",title:"申请总人数",align:'center',width:150},
            {field:"applyPass",title:"通过人数",align:'center',width:150,templet:function(data){
                if(data.applyPass!==0){
                    return data.applyPass;
                }else{
                    return "0";
                }
             }},
            {field:"applyRejection",title:"未通过人数",align:'center',width:150,templet:function(data){
                if(data.applyRejection!==0){
                    return data.applyRejection;
                }else{
                    return "0";
                }
             }},
            {field:"applyPosition",title:"申请的职位",align:'center',width:140,templet:function(data){
                if(data.applyPosition){
                    return data.applyPosition;
                }else{
                    return "教师";
                }
             }}
        ]]
    });
}
/**
 *  申请人统计图
 */
function selEcharts(durDate){
    $.ajax({
        url:"/personnel/selEcharts",
        type:"post",
        dataType:"json",
        data:{"durDate":durDate},
        success:function(data) {
            selEchart(data);
        }
    })
}
function selEchart(data){
    var chartDom = document.getElementById('selEcharts');
    var myChart = echarts.init(chartDom);
    var option;
    option = {
        title: {
            text: '申请人数统计',
            subtext: '数据统计',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
        },
        series: [
            {
                name: '申请人数统计',
                type: 'pie',
                radius: '55%',
                roseType: 'angle',
                data: [
                    {value: data.applyNum, name: '申请总人数'},
                    {value: data.applyPass, name: '通过申请人数'},
                    {value: data.applyRejection, name: '申请驳回人数'}
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    option && myChart.setOption(option);
}
/**
 *  用户统计图
 * */
function selUserEcharts(){
    $.ajax({
        url:"/personnel/selUserEcharts",
        type:"get",
        dataType:"json",
        data:{},
        success:function(data) {
            userEcharts(data);
        }
    })
}
function userEcharts(data){
    var chartDom = document.getElementById('userecharts');
    var myChart = echarts.init(chartDom);
    var option;
    option = {
        title: {
            text: '用户统计图'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        legend: {
            data: ['用户']
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '用户',
                type: 'line',
                stack: '总量',
                areaStyle: {},
                emphasis: {
                    focus: 'series'
                },
                data: data
            }
        ]
    };
    option && myChart.setOption(option);
}